package oop.ex2.commands;

import oop.ex2.exceptions.EmptyExpression;
import oop.ex2.exceptions.ExpectedAtomicExpression;
import oop.ex2.exceptions.ExpectedBinaryOperation;
import oop.ex2.exceptions.TerminatingStringNotFound;
import oop.ex2.exceptions.TokenNotRecognized;
import oop.ex2.exceptions.UnrecognizedVariable;
import oop.ex2.expression.ExpressionSolver;

/**
 * This is the base class for all of the different commands that can be called. In this case,
 * the commands are "inline", "overload", "assignment" and an expression.
 * Each command holds an ExpressionSolver which it acts upon - i.e - it updates that solver's
 * variables and functions.
 * @author daniel_i_l
 *
 */
public abstract class Command {
	protected ExpressionSolver _expressionSolver;
	
	/**
	 * Builds a command using the specified ExpressionSolver.
	 * @param expressionSolver The expression solver to store.
	 */
	public Command(ExpressionSolver expressionSolver)
	{
		_expressionSolver = expressionSolver;
	}
	
	/**
	 * Executes a given command.
	 * @param command The command to execute.
	 * @return true if the command was recognized and false otherwise.
	 * @throws UnrecognizedVariable if an unrecognized variable is encountered during the calculation 
	 * @throws TerminatingStringNotFound if the end of an sequence was expected and not found.
	 * @throws ExpectedBinaryOperation if a binary operation was expected and not found.
	 * @throws ExpectedAtomicExpression if an atomic symbol was expected and not found.
	 * @throws EmptyExpression an empty expression was encountered.
	 * @throws TokenNotRecognized if an unrecognized token was encountered.
	 */
	public abstract boolean executeCommand(String command) throws TokenNotRecognized, EmptyExpression, ExpectedAtomicExpression, ExpectedBinaryOperation, TerminatingStringNotFound, UnrecognizedVariable;
}
